function isEmpty(value) {
    return value === 0 ? false : (value == null || String(value).trim().length == 0);
}

/**
 * 创建正则
 * @param str
 * @returns {*}
 */
export default function createRegExp(str) {

  if (isEmpty(str)) {
      return null;
  }

  switch (str) {

      case 'safe':
          return /^[\u4E00-\u9FFFa-zA-Z0-9~@#%!_\.+-]+$/;
      case 'zh':
          return /^[\u4E00-\u9FFF]+$/;
      case 'email':
          return /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
      case 'website':
          return /^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%$#=~_-]*)?$/;
      case 'url':
          return /^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%$#=~_-]*)?$/;
      case 'number':
          return /^[0-9\.]+$/;
      case 'all_num':
          return /^[0-9]+$/;
      case 'en_number': //英文+数字
          return /^[a-zA-Z\d]+$/;
      case 'id':
      case 'idcard':
          return /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/; //身份证
      case 'tel':
          return /^[0-9\#\-\+\s]{6,20}$/;
      case 'phone':
      case 'mobile':
          return /^[16][3-9]\d{9}$/;
      case 'bank':
          return /^([1-9]{1})(\d{14}|\d{18})$/;
      case 'username':
          return /^(\w){6,50}$/;
      case 'money':
          return /^[0-9]{1,8}([.][0-9]{1,4})?$/;
      case 'password':
          return /^[A-Za-z]{1}[a-zA-Z0-9~@#%&*!_+-\.]{7,50}$/;
      case 'temperature':
          return /^[3|4]\d(\.\d)?$/;
      case 'ip': // ip 地址
          return /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
      case 'card': // 身份证、护照、通行证
          return /^[a-zA-Z0-9]{3,21}$/;
      default:
          return new RegExp(str);

  }

}
